cmake_minimum_required(VERSION 3.27)
project(Osg3D)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

add_definitions(-DProject_KT)

set(CMAKE_PREFIX_PATH "D:/Qt5.12.5/5.12.5/msvc2017_64/lib/cmake")

set(OSG_PATH "D:/OSG3.7/vs2022/install")
set(SDL3_PATH "D:/SDL3-devel-3.2.14-VC/SDL3-3.2.14")

link_directories("${OSG_PATH}/lib" "${SDL3_PATH}/lib/x64")

function(add_folder_as_target folder)
	file(GLOB FILES "${folder}/*")
	string(REPLACE "/" "_" target_name ${folder})
	add_custom_target(${target_name} SOURCES ${FILES})
endfunction()
add_folder_as_target("res/qml")
add_folder_as_target("res/glsl")
add_folder_as_target("res/object")
add_folder_as_target("res/image")
add_folder_as_target("res/file")

add_custom_target("ToDo" SOURCES "ToDo.md")

file(GLOB_RECURSE SRC_FILES "src/*")
file(GLOB_RECURSE INCLUDE_SRC_FILES "external/src/*" "external/sol/lua/*.c")

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src FILES ${SRC_FILES})

file(GLOB_RECURSE TEST_SRC_FILES "test/*")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/test FILES ${TEST_SRC_FILES})

add_executable(${PROJECT_NAME} ${SRC_FILES} main.cpp ${TEST_SRC_FILES})
target_sources(${PROJECT_NAME} PRIVATE ${INCLUDE_SRC_FILES})

find_package(Qt5 COMPONENTS Core Quick Qml Gui Concurrent Network REQUIRED)
find_package(OpenGL REQUIRED) #OpenGL not Qt5 OpenGL

if (Qt5Core_FOUND OR Qt6Core_FOUND)
	add_definitions(-D__QT__)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE "${OSG_PATH}/include" "external" "external/sol" "${SDL3_PATH}/include")

target_link_libraries(${PROJECT_NAME}
	Qt5::Core Qt5::Quick Qt5::Qml Qt5::Gui Qt5::Concurrent Qt5::Network
	${OPENGL_LIBRARIES}
	SDL3.lib
	OpenThreadsd.lib
	osgd.lib
	osgUtild.lib
	osgDBd.lib
	osgGAd.lib
	osgViewerd.lib
	osgTextd.lib
	osgAnimationd.lib
	osgVolumed.lib
	osgManipulatord.lib
	osgTerraind.lib
	osgShadowd.lib
	osgParticled.lib
	osgSimd.lib
	osgFXd.lib
)